import http from '../../../../util/http.js';


//获取公众号配置文件
export function findWxmpConfig(postData) {
    let url = `/weixin/mp/config/find`;
    return new Promise((resolve, reject) => {
        http.get(url, postData).then(response => {
            resolve(response)
        })
    });
}

//新增公众号配置信息
export function addWxmpConfig(postData) {
    let url = `/weixin/mp/config/add`;
    return new Promise((resolve, reject) => {
        http.post(url, postData).then(response => {
            resolve(response)
        })
    });
}


//根据公众号ID修改公众号信息
export function updateWxmpConfig(id, param) {
    let url = `/weixin/mp/config/update/${id}`;
    return new Promise((resolve, reject) => {
        http.put(url, param).then(response => {
            resolve(response)
        })
    });
}


//================素材管理API接口==================

//获取分组列表
export function materialList(pagination, param) {
    let url = `/weixin/mp/material/list/${pagination.pageSize}/${pagination.current}`;
    return new Promise((resolve, reject) => {
        http.get(url, param).then(response => {
            resolve(response)
        });
    });
}

//同步微信服务器的素材到数据库
export function syncMaterialFile(mediaType) {
    let url = `/weixin/mp/material/sync/${mediaType}`;
    return new Promise((resolve, reject) => {
        http.get(url).then(response => {
            resolve(response)
        });
    });
}

//添加文件素材
export function addFileMaterial(file) {

    let url = '/weixin/mp/material/addFile';
    return new Promise((resolve, reject) => {
        http.upload(url, file).then(response => {
            resolve(response)
        });
    });
}


//添加图文素材
export function addNewsMaterial(data) {

    let url = '/weixin/mp/material/addNews';
    return new Promise((resolve, reject) => {
        http.post(url, data).then(response => {
            resolve(response)
        });
    });
}


//修改图文素材
export function updateMaterialArticle(data) {

    let url = '/weixin/mp/material/updateNews';
    return new Promise((resolve, reject) => {
        http.put(url, data).then(response => {
            resolve(response)
        });
    });
}


//根据微信素材ID删除素材
export function deleteMaterial(mediaId) {
    let url = `/weixin/mp/material/delete/${mediaId}`;
    return new Promise((resolve, reject) => {
        http.delete(url).then(response => {
            resolve(response)
        });
    });
}


//=========================自动回复开始=======================


export function replyList(pagination, param) {
    let url = `/weixin/mp/reply/list/${pagination.pageSize}/${pagination.current}`;
    return new Promise((resolve, reject) => {
        http.get(url, param).then(response => {
            resolve(response)
        });
    });
}


//新增公众号配置信息
export function replyAdd(postData) {
    let url = `/weixin/mp/reply/add`;
    return new Promise((resolve, reject) => {
        http.post(url, postData).then(response => {
            resolve(response)
        })
    });
}


//根据公众号ID修改公众号信息
export function replyUpdate(id, param) {
    let url = `/weixin/mp/reply/update/${id}`;
    return new Promise((resolve, reject) => {
        http.put(url, param).then(response => {
            resolve(response)
        })
    });
}


//根据关键字ID删除回复设置
export function replyDelete(id) {
    let url = `/weixin/mp/reply/delete/${id}`;
    return new Promise((resolve, reject) => {
        http.delete(url).then(response => {
            resolve(response)
        });
    });
}


//=============标签管理===================
//获取公众号标签列表
export function tagList(pagination, param) {
    let url = `/weixin/mp/tag/list/${pagination.pageSize}/${pagination.current}`;
    return new Promise((resolve, reject) => {
        http.get(url, param).then(response => {
            resolve(response)
        });
    });
}

//新增公众号配置信息
export function tagAdd(postData) {
    let url = `/weixin/mp/tag/add`;
    return new Promise((resolve, reject) => {
        http.post(url, postData).then(response => {
            resolve(response)
        })
    });
}

//根据公众号ID修改公众号信息
export function tagSync() {
    let url = `/weixin/mp/tag/sync`;
    return new Promise((resolve, reject) => {
        http.get(url).then(response => {
            resolve(response)
        })
    });
}


//根据公众号ID修改公众号信息
export function tagUpdate(id, param) {
    let url = `/weixin/mp/tag/update/${id}`;
    return new Promise((resolve, reject) => {
        http.put(url, param).then(response => {
            resolve(response)
        })
    });
}

//删除标签
export function tagDelete(id) {
    let url = `/weixin/mp/tag/delete/${id}`;
    return new Promise((resolve, reject) => {
        http.delete(url).then(response => {
            resolve(response)
        })
    });
}

//==================公众号 用户管理==============

//同步公众号用户
export function userSyncBatch() {
    let url = `/weixin/mp/user/batch/sync`;
    return new Promise((resolve, reject) => {
        http.get(url).then(response => {
            resolve(response)
        });
    });
}

export function userSync(openId) {
    let url = `/weixin/mp/user/one/sync/${openId}`;
    return new Promise((resolve, reject) => {
        http.get(url).then(response => {
            resolve(response)
        });
    });
}


//公众号关注用户列表
export function userList(pagination, param) {
    let url = `/weixin/mp/user/list/${pagination.pageSize}/${pagination.current}`;
    return new Promise((resolve, reject) => {
        http.get(url, param).then(response => {
            resolve(response)
        });
    });
}


//根据修改用户
export function userUpdate(id, param) {
    let url = `/weixin/mp/user/update/${id}`;
    return new Promise((resolve, reject) => {
        http.put(url, param).then(response => {
            resolve(response)
        })
    });
}




//批量设置用户标签
export function batchupTags(param) {
    let url = `/weixin/mp/user/batch/update/tags`;
    return new Promise((resolve, reject) => {
        http.put(url, param).then(response => {
            resolve(response)
        });
    });

}


//=============公众号个性化菜单==========



//根据标签ID获取菜单按钮
export function getMenuButtons(tagId) {
    let url = `/weixin/mp/menu/buttons/${tagId}`;
    return new Promise((resolve, reject) => {
        http.get(url).then(response => {
            resolve(response)
        });
    });
}


//根据标签ID获取菜单按钮
export function saveMenuButton(data) {
    let url = `/weixin/mp/menu/save`;
    return new Promise((resolve, reject) => {
        http.post(url,data).then(response => {
            resolve(response)
        });
    });
}

//删除公众号个性化菜单
export  function  deleteMenu() {
    let url = `/weixin/mp/menu/delete`;
    return new Promise((resolve, reject) => {
        http.delete(url).then(response => {
            resolve(response)
        });
    });

}